﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CygwinPackageManager.Common;
using CygwinPackageManager.Properties;
using System.Diagnostics;

namespace CygwinPackageManager
{
	[Docking(DockingBehavior.Ask)]
	public partial class PackageDetails : UserControl
	{
		public PackageDetails()
		{
			InitializeComponent();
		}

		#region Public Properties
		private IEnumerable<PackageInfo> _requirements;
		[Browsable(false)]
		[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
		public IEnumerable<PackageInfo> Requirements
		{
			get { return _requirements; }
			set
			{
				SetRequirements(value);

				_requirements = value;
			}
		}
		private IEnumerable<PackageInfo> _packages;
		[Browsable(false)]
		[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
		public IEnumerable<PackageInfo> Packages
		{
			get { return _packages; }
			set
			{
				SetDetails(value);

				_packages = value;
			}
		}
		#endregion

		#region Private Methods
		private void SetRequirements(IEnumerable<PackageInfo> value)
		{
			if (value == null)
			{
				packageGrid1.Packages = null;
			}
			else
			{
				SearchableSortableBindingList<PackageInfo> requirementsBindingList = new SearchableSortableBindingList<PackageInfo>();
				requirementsBindingList.AddRange(value);
				packageGrid1.Packages = requirementsBindingList;
			}
		}

		private void SetDetails(IEnumerable<PackageInfo> value)
		{
			if (value == null)
			{
				tbDetails.Text = string.Empty;
			}
			else
			{
				tbDetails.Text = value.GetDetails();
			}
		}
		#endregion
	}
}
